package org.hylexus.hadoop.hadoop_2_test.mr.demo2;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

public class DataBean implements Writable {

	private String phone;
	private long up;
	private long down;

	private long total;

	public DataBean() {
	}

	public DataBean(String phone, long up, long down) {
		super();
		this.phone = phone;
		this.up = up;
		this.down = down;
		this.total = this.up + this.down;
	}

	// 序列化
	@Override
	public void write(DataOutput out) throws IOException {
		out.writeUTF(phone);
		out.writeLong(up);
		out.writeLong(down);
		out.writeLong(total);
	}

	// 反序列化
	@Override
	public void readFields(DataInput in) throws IOException {

		this.phone = in.readUTF();
		this.up = in.readLong();
		this.down = in.readLong();
		this.total = in.readLong();
	}

	public long getUp() {
		return up;
	}

	public void setUp(long up) {
		this.up = up;
	}

	public long getDown() {
		return down;
	}

	public void setDown(long down) {
		this.down = down;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public long getTotal() {
		return up + down;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	@Override
	public String toString() {
		return phone + "\t" + up + "\t" + down + "\t" + total;
	}

}
